package com.sync.platform.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.sync.platform.entity.SyncTask;

import java.util.List;
import java.util.Map;

/**
 * Sync task service interface
 */
public interface SyncTaskService extends IService<SyncTask> {

    /**
     * Save database sync task
     *
     * @param syncTask Sync task entity
     * @param sourceTables Selected source tables (null for all tables)
     * @param createTableIfNotExists Whether to create target tables if not exist
     * @param truncateBeforeSync Whether to truncate target tables before sync
     * @return true if save successful, false otherwise
     */
    boolean saveDatabaseSyncTask(SyncTask syncTask, List<String> sourceTables, 
                                boolean createTableIfNotExists, boolean truncateBeforeSync);

    /**
     * Save database sync task with incremental sync option
     *
     * @param syncTask Sync task entity
     * @param sourceTables Selected source tables (null for all tables)
     * @param createTableIfNotExists Whether to create target tables if not exist
     * @param truncateBeforeSync Whether to truncate target tables before sync
     * @param incrementalSync Whether to use incremental sync
     * @param incrementalColumn Column name for incremental sync (usually a timestamp column)
     * @return true if save successful, false otherwise
     */
    boolean saveDatabaseSyncTask(SyncTask syncTask, List<String> sourceTables, 
                                boolean createTableIfNotExists, boolean truncateBeforeSync,
                                boolean incrementalSync, String incrementalColumn);

    /**
     * Get database sync tasks
     *
     * @return List of database sync tasks
     */
    List<SyncTask> getDatabaseSyncTasks();

    /**
     * Get file sync tasks
     *
     * @return List of file sync tasks
     */
    List<SyncTask> getFileSyncTasks();

    /**
     * Save file sync task
     *
     * @param syncTask Sync task entity
     * @param sourcePath Source path on source server
     * @param targetPath Target path on target server
     * @param filePattern Optional file pattern for filtering (null for all files)
     * @param transferType Transfer type (ssh or ftp)
     * @param deleteSource Whether to delete source files after synchronization
     * @param syncDirectories Whether to sync directories and maintain directory structure
     * @return Result map with success flag and message
     */
    Map<String, Object> saveFileSyncTask(SyncTask syncTask, String sourcePath, String targetPath, String filePattern,
                                        String transferType, String deleteSource, String syncDirectories);

    /**
     * Execute sync task
     *
     * @param id Sync task ID
     * @return Execution result
     */
    Map<String, Object> executeTask(Long id);

    /**
     * Enable or disable sync task
     *
     * @param id Sync task ID
     * @param status Status to set (0: disabled, 1: enabled)
     * @return true if update successful, false otherwise
     */
    boolean updateTaskStatus(Long id, Integer status);
    
    /**
     * Count database sync tasks
     *
     * @return Number of database sync tasks
     */
    int countDatabaseSyncTasks();
    
    /**
     * Count file sync tasks
     *
     * @return Number of file sync tasks
     */
    int countFileSyncTasks();
}
